<template>
    <div>
      <h2 style="text-align: center;">航班列表</h2>
      <el-row :gutter="20">       
       <el-col :span="24">
        <!-- 添加/批量删除按钮 -->
         <div>
          <el-button @click="toAddFlight" type="primary" size="small">添加航班</el-button>
          <el-button @click="batchDeleteFlight" type="danger" size="small">批量删除航班</el-button>
          <el-button @click="toSelectFlight" type="primary" size="small">查询航班</el-button>
          <el-button type="text" icon="el-icon-refresh" :style="{ fontSize: '24px', padding: '10px' }" @click="refreshBtn"></el-button>
         </div>
        <el-table
      :data="flightList"
      style="width: 100%"
      @selection-change="handleSelectionChange"
      >
      <el-table-column
      type="selection"
      width="55">
    </el-table-column>
      <el-table-column
        prop="flightNumber"
        label="航班号"
        width="100">
        
      </el-table-column>
      <el-table-column
        prop="airline"
        label="航空公司"
        width="120">
      
      </el-table-column>
      <el-table-column
        prop="departureCity"
        label="出发地"
        width="100">
      </el-table-column>
      <el-table-column
        prop="departureAirport"
        label="出发机场"
        width="140">
      </el-table-column>
      <el-table-column
        prop="arrivalCity"
        label="目的地"
        width="100">
      </el-table-column>
      <el-table-column
        prop="arrivalAirport"
        label="目的机场"
        width="140">
      </el-table-column>
      <el-table-column
        prop="departureTime"
        label="起飞时间"
        width="180">
      </el-table-column>
      <el-table-column
        prop="arrivalTime"
        label="到达时间"
        width="180">
      </el-table-column>
      <el-table-column
        prop="status"
        label="航班状态"
        width="100">
      </el-table-column>
      <el-table-column
      label="操作"
      width="140"
      fixed="right">
      <template v-slot="props">
        <el-button @click="toEditFlight(props.row)" type="primary" icon="el-icon-edit" circle></el-button>
        <el-button @click="deleteFlight(props.row.flightId)" type="danger" icon="el-icon-delete" circle></el-button>
        <el-button type="text" @click="Toticket(props.row.flightId)">查看机票</el-button>
      </template>
      </el-table-column>
    </el-table>
   <el-row style="margin-top: 10px;text-align: center;" >
    <el-pagination
  background
  layout="prev, pager, next"
  :total="total"
  :page-size="pageSize"
  prev-text="上一页"
  next-text="下一页"
  @next-click="getFlightPage(pageNo+1,pageSize)"
  @prev-click="getFlightPage(pageNo-1,pageSize)"
  @current-change="handleCurrentChange"
  v-if="isPaginationVisable">
</el-pagination>
   </el-row>
       </el-col>
      </el-row>
      <!-- 添加航班Dialog -->
  <el-dialog title="添加航班" :visible.sync="dialogTableVisible" width="%40" @close="resetForm('flightForm')">
        <el-form :model="flight" :rules="rules" ref="flightForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="航班号" prop="flightNumber">
    <el-input v-model="flight.flightNumber" placeholder="请输入航班号"></el-input>
  </el-form-item>
  <el-form-item label="航空公司" prop="airline">
    <el-input v-model="flight.airline" placeholder="请输入航空公司"></el-input>
  </el-form-item>
  <el-form-item label="出发地" prop="departureAirport">
    <el-select   placeholder="请选择出发地" v-model="flight.departureCity"  >
        <el-option v-for="timezone in cityList" :key="timezone.cityId"  :label="`${timezone.city} (${timezone.timezoneId})`" :value="timezone.city" size="medium"></el-option>
      </el-select>
    </el-form-item>
  <el-form-item label="出发机场" prop="departureAirport">
    <el-input v-model="flight.departureAirport" placeholder="请输入出发机场名"></el-input>
  </el-form-item>
  <el-form-item label="目的地" prop="arrivalAirport">
    <el-select   placeholder="请选择出发地" v-model="flight.arrivalCity"  >
        <el-option v-for="timezone in cityList" :key="timezone.cityId"  :label="`${timezone.city} (${timezone.timezoneId})`" :value="timezone.city" size="medium"></el-option>
      </el-select>
    </el-form-item>
  <el-form-item label="目的机场" prop="arrivalAirport">
    <el-input v-model="flight.arrivalAirport" placeholder="请输入目的机场名"></el-input>
  </el-form-item>
  <el-form-item label="航班状态" prop="status">
    <el-select v-model="flight.status" placeholder="请选择航班状态">
      <el-option label="计划" value="计划"></el-option>
      <el-option label="延误" value="延误"></el-option>
      <el-option label="取消" value="取消"></el-option>
      <el-option label="到达" value="到达"></el-option>
      <el-option label="起飞" value="起飞"></el-option>
      <el-option label="到达" value="到达"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="起飞时间（北京时间）" prop="departureTime">
    <el-date-picker
      v-model="flight.departureTime"
      type="datetime"
      value-format="yyyy-MM-dd HH:mm:ss"
       :picker-options="pickerOptions"
      placeholder="选择日期时间">
    </el-date-picker>
  </el-form-item>
  <el-form-item label="到达时间（北京时间）" prop="arrivalTime">
    <el-date-picker
      v-model="flight.arrivalTime"
      value-format="yyyy-MM-dd HH:mm:ss"
       :picker-options="pickerOptions"
      type="datetime"
      placeholder="选择日期时间">
    </el-date-picker>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click=" addFlightBtn('flightForm')">添加</el-button>
    <el-button @click="resetForm('flightForm')">重置</el-button>
  </el-form-item>
</el-form>
      </el-dialog>
      <!-- 更新航班Dialog -->
      <el-dialog title="更新航班" :visible.sync="dialogTableVisibleUpdate" width="%40" @close="resetForm('flightForm')">
        <el-form :model="flight" :rules="rules" ref="flightForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="航班Id" prop="flightId">
    <el-input v-model="flight.flightId" disabled></el-input>
  </el-form-item>        
  <el-form-item label="航班号" prop="flightNumber">
    <el-input v-model="flight.flightNumber" placeholder="请输入航班号"></el-input>
  </el-form-item>
  <el-form-item label="航空公司" prop="airline">
    <el-input v-model="flight.airline" placeholder="请输入航空公司"></el-input>
  </el-form-item>
  <el-form-item label="出发地" prop="departureAirport">
    <el-select   placeholder="请选择出发地" v-model="flight.departureCity"  >
        <el-option v-for="timezone in cityList" :key="timezone.cityId"  :label="`${timezone.city} (${timezone.timezoneId})`" :value="timezone.city" size="medium"></el-option>
      </el-select>
    </el-form-item>
  <el-form-item label="出发机场" prop="departureAirport">
    <el-input v-model="flight.departureAirport" placeholder="请输入出发机场名"></el-input>
  </el-form-item>
  <el-form-item label="目的地" prop="arrivalAirport">
    <el-select   placeholder="请选择出发地" v-model="flight.arrivalCity"  >
        <el-option v-for="timezone in cityList" :key="timezone.cityId"  :label="`${timezone.city} (${timezone.timezoneId})`" :value="timezone.city" size="medium"></el-option>
      </el-select>
    </el-form-item>
  <el-form-item label="目的机场" prop="arrivalAirport">
    <el-input v-model="flight.arrivalAirport" placeholder="请输入目的机场名"></el-input>
  </el-form-item>
  <el-form-item label="航班状态" prop="status">
    <el-select v-model="flight.status" placeholder="请选择航班状态">
      <el-option label="计划" value="计划"></el-option>
      <el-option label="延误" value="延误"></el-option>
      <el-option label="取消" value="取消"></el-option>
      <el-option label="到达" value="到达"></el-option>
      <el-option label="起飞" value="起飞"></el-option>
      <el-option label="到达" value="到达"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="起飞时间（北京时间）" prop="departureTime">
    <el-date-picker
      v-model="flight.departureTime"
      type="datetime"
      value-format="yyyy-MM-dd HH:mm:ss"
      placeholder="选择日期时间"
      :picker-options="pickerOptions">
    </el-date-picker>
  </el-form-item>
  <el-form-item label="到达时间（北京时间）" prop="arrivalTime">
    <el-date-picker
      v-model="flight.arrivalTime"
      value-format="yyyy-MM-dd HH:mm:ss"
      type="datetime"
      placeholder="选择日期时间"
      :picker-options="pickerOptions">
    </el-date-picker>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click=" updateFlightBtn">更新</el-button>
    <el-button @click="dialogTableVisibleUpdate=false">取消</el-button>
  </el-form-item>
</el-form>
      </el-dialog>
      <!-- 添加航班后添加机票Dialog -->
      <el-dialog title="添加机票信息" :visible.sync="dialogTableVisibleAddTicket" width="%40" @close="resetForm('ticketForm')">
        <el-form :model="ticket"  ref="ticketForm" label-width="100px" class="demo-ruleForm" :rules="ticketRules">
  <el-form-item label="机票价格" prop="price">
    <el-input v-model="ticket.price" placeholder="请输入机票价格"></el-input>
  </el-form-item>
  <el-form-item label="机票数量" prop="count">
    <el-input v-model="ticket.count" placeholder="请输入机票数量"></el-input>
  </el-form-item>
  <el-form-item label="机票类型" prop="status">
    <el-select v-model="ticket.type" placeholder="请选择机票种类">
      <el-option label="经济舱" value="经济舱"></el-option>
      <el-option label="头等舱" value="头等舱"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click=" addTicketAndFlightBtn('ticketForm')">添加</el-button>
  </el-form-item>
</el-form>
      </el-dialog>
      <!-- 添加机票Dialog -->
      <el-dialog title="添加机票信息" :visible.sync="dialogTableVisibleAddTicket1" width="%40" @close="resetForm('ticketForm')">
        <el-form :model="ticket"  ref="ticketForm" label-width="100px" class="demo-ruleForm" :rules="ticketRules">
  <el-form-item label="机票价格" prop="price">
    <el-input v-model="ticket.price" placeholder="请输入机票价格"></el-input>
  </el-form-item>
  <el-form-item label="机票数量" prop="count">
    <el-input v-model="ticket.count" placeholder="请输入机票数量"></el-input>
  </el-form-item>
  <el-form-item label="机票类型" prop="status">
    <el-select v-model="ticket.type" placeholder="请选择机票种类">
      <el-option label="经济舱" value="经济舱"></el-option>
      <el-option label="头等舱" value="头等舱"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="addTicketBtn('ticketForm')">添加</el-button>
    <el-button @click="resetForm('ticketForm')">重置</el-button>
  </el-form-item>
</el-form>
      </el-dialog>
      <!-- 更新机票Dialog -->
      <el-dialog title="更新机票信息" :visible.sync="dialogTableVisibleUpdateTicket" width="%40" @close="resetForm('ticketForm')">
        <el-form :model="ticket"  ref="ticketForm" label-width="100px" class="demo-ruleForm" :rules="ticketRules">
  <el-form-item label="机票价格" prop="price">
    <el-input v-model="ticket.price" placeholder="请输入机票价格"></el-input>
  </el-form-item>
  <el-form-item label="机票数量" prop="count">
    <el-input v-model="ticket.count" placeholder="请输入机票数量"></el-input>
  </el-form-item>
  <el-form-item label="机票类型" prop="status">
    <el-select v-model="ticket.type" placeholder="请选择机票种类">
      <el-option label="经济舱" value="经济舱"></el-option>
      <el-option label="头等舱" value="头等舱"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click=" updateTicketBtn">更新</el-button>
    <el-button @click="dialogTableVisibleUpdateTicket=false">取消</el-button>
  </el-form-item>
</el-form>
      </el-dialog>
      <!-- 查询航班Dialog -->
      <el-dialog title="查询航班信息" :visible.sync="dialogTableVisibleSelect" width="%40" @close="resetForm('flightForm')">
        <el-form :model="flight"  ref="flightForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="航班号" prop="flightNumber">
    <el-input v-model="flight.flightNumber" placeholder="请输入航班号"></el-input>
  </el-form-item>
  <el-form-item label="航空公司" prop="airline">
    <el-input v-model="flight.airline" placeholder="请输入航空公司"></el-input>
  </el-form-item>
  <el-form-item label="出发地" prop="departureCity">
    <el-input v-model="flight.departureCity" placeholder="请输入出发城市名"></el-input>
  </el-form-item>
  <el-form-item label="出发机场" prop="departureAirport">
    <el-input v-model="flight.departureAirport" placeholder="请输入出发机场名"></el-input>
  </el-form-item>
  <el-form-item label="目的地" prop="arrivalCity">
    <el-input v-model="flight.arrivalCity" placeholder="请输入目的城市名"></el-input>
  </el-form-item>
  <el-form-item label="目的机场" prop="arrivalAirport">
    <el-input v-model="flight.arrivalAirport" placeholder="请输入目的机场名"></el-input>
  </el-form-item>
  <el-form-item label="航班状态" prop="status">
    <el-select v-model="flight.status" placeholder="请选择航班状态">
      <el-option label="计划" value="计划"></el-option>
      <el-option label="延误" value="延误"></el-option>
      <el-option label="取消" value="取消"></el-option>
      <el-option label="到达" value="到达"></el-option>
      <el-option label="起飞" value="起飞"></el-option>
      <el-option label="到达" value="到达"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="起飞时间（北京时间）" prop="departureTime">
    <template>
  <el-date-picker
    v-model="flight.departureTime"
    type="datetime"
    value-format="yyyy-MM-dd HH:mm:ss"
    placeholder="选择日期时间"
     :picker-options="pickerOptions"
    >
  </el-date-picker>
</template>
  </el-form-item>
  <el-form-item label="到达时间（北京时间）" prop="arrivalTime">
    <el-date-picker
      v-model="flight.arrivalTime"
      value-format="yyyy-MM-dd HH:mm:ss"
      type="datetime"
       :picker-options="pickerOptions"
      placeholder="选择日期时间">
    </el-date-picker>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="selectFlightBtn('flightForm')">查询</el-button>
    <el-button @click="resetForm('flightForm')">重置</el-button>
  </el-form-item>
</el-form>
      </el-dialog>
      <!-- 查看机票Drawer -->
      <el-drawer
  title="当前航班机票列表"
  :visible.sync="ticketDrawer"
  direction="rtl"
  size="50%">
  <el-button type="primary" @click="dialogTableVisibleAddTicket1=true">添加机票<i class="el-icon-upload el-icon--right"></i></el-button>
   <el-table :data="ticketList">
      <el-table-column property="type" label="类型" width="150"></el-table-column>
      <el-table-column property="count" label="剩余数量" width="150"></el-table-column>
      <el-table-column property="price" label="价格" width="150"></el-table-column>
      <el-table-column
      label="操作"
      width="140"
      fixed="right">
      <template v-slot="props">
        <el-button @click="toEditTicket(props.row)" type="primary" icon="el-icon-edit" circle></el-button>
        <el-button @click="deleteTicket(props.row)" type="danger" icon="el-icon-delete" circle></el-button>
      </template>
      </el-table-column>

    </el-table>
</el-drawer>
    </div>
</template>
  <script>
  import axios from 'axios';
 
    export default {
      data() {
        return {
          pickerOptions: {
        disabledDate(time) {
          // 只能选择今天之后的时间
          const today = new Date();
          today.setHours(0, 0, 0, 0); // 设置到今天的开始时间（00:00:00）
          return time.getTime() < today.getTime();
        }
      },
          ticketList:[],
          flightList:[],
          pageNo:1,
          pageSize:8,
          total:0,
          flightIds:[],
          dialogTableVisible:false,
          dialogTableVisibleSelect:false,
          dialogTableVisibleAddTicket:false,
          dialogTableVisibleUpdateTicket:false,
          dialogTableVisibleAddTicket1:false,
          isPaginationVisable:true,
          ticketDrawer:false,
          timezone:{
            cityId:undefined,
            city:'',
            timezoneId:''
          },
          cityList:[],
          flight:{
            flightId:undefined,
            flightNumber:'',
            airline:'',
            departureCity:'',
            arrivalCity:'',
            departureAirport:'',
            arrivalAirport:'',
            status:'',
            departureTime:'',
            arrivalTime:'',
          },
          ticket:{
            ticketId:undefined,
            flightId:undefined,
            price:'',
            type:'',
            count:'',
          },
          rules:{
            flightNumber:[
            { required: true, message: '请输入航班号', trigger: 'blur' },
            ],
            airline:[
            { required: true, message: '请输入航班号', trigger: 'blur' },
            ],
            departureCity:[
            { required: true, message: '请输入城市名', trigger: 'blur' },
            ],
            arrivalCity:[
            { required: true, message: '请输入城市名', trigger: 'blur' }
            ],
            departureAirport:[
            { required: true, message: '请输入机场名', trigger: 'blur' }
            ],
            arrivalAirport:[
            { required: true, message: '请输入机场名', trigger: 'blur' }
            ],
            departureTime: [
            { required: true, message: '请选择起飞时间', trigger: 'change' }
            ],
            arrivalTime: [
            { required: true, message: '请选择起飞时间', trigger: 'change' }
            ],
            status: [
            { required: true, message: '请选择航班状态', trigger: 'change' }
            ],
          },
          ticketRules:{
            price:[
            { required: true, message: '请输入机票价格', trigger: 'change' }
            ],
            count:[
            { required: true, message: '请输入机票数量', trigger: 'change' }
            ],
            type:[
            { required: true, message: '请选择机票类型', trigger: 'change' }
            ]
          },
          dialogTableVisibleUpdate:false
        }
      },
      mounted(){
        this.getFlightPage(this.pageNo,this.pageSize);
        this.getCityList();
      },
      methods:{
       
        /**
         * 获取城市列表
         */
        getCityList(){
          axios.get("http://localhost:8082/timezone/getCityList",{
         
        }
        ).then(resp=>{
          console.log("999999----------=======",resp)
          this.cityList=resp.data.data
        })
        },
        /**
         * 查看机票按钮
         */
        Toticket(flightId){
          this.flight.flightId=flightId,
          console.log("2222222222========",this.flight.flightId)
          this.ticketDrawer=true;
          console.log(flightId)
          axios.get("http://localhost:8082/ticket/selectTicketByFlightId",{
            params:{
              flightId:flightId
            }
          }).then(resp=>{
            console.log("------->",resp)
            this.ticketList=resp.data.data
            console.log("1111111111========",flightId)
            this.flight.flightId=flightId
          })
        },
        /**
         * 刷新按钮事件
         */
         refreshBtn(){
          this.getFlightPage(this.pageNo,this.pageSize);
          this.isPaginationVisable=true
         },
        /**
         * 多选事件处理
         */
        handleSelectionChange(val){
          this.flightIds=[],
          val.forEach(element => {
            this.flightIds.push(element.flightId)
          });
          
        },
        /**
         * 批量删除
         */
        batchDeleteFlight(){
          if(this.flightIds&&this.flightIds.length===0){
            this.$message({
            type: 'error',
            message: '请选择要删除的数据!'
          })
          }else{
          this.$confirm('是否批量删除', '删除提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
          }).then(() => {
          //确定删除
          axios.post("http://localhost:8082/flight/batchDeleteFlight",JSON.stringify(this.flightIds),{
            headers:{
              'Content-Type':'application/json'
            }
          }).then(resp=>{
            if(resp.data.code===0){
              this.$message({
            type: 'success',
            message: '删除成功'
          });
          this.getFlightPage(this.pageNo,this.pageSize)
            }else{
              this.$message({
              type: 'error',
              message: resp.data.message
          })
            }
          })
        }).catch(() => {
          this.$message({
            type: 'error',
            message: '已取消删除'
          });          
        });}
        },
        /**
         * 处理当前页
         */
        handleCurrentChange(current){
          this.pageNo=current
          this.getFlightPage(this.pageNo,this.pageSize)
        },
        /**
         * 分页获取航班信息的函数
         */
        getFlightPage(pageNo,pageSize){
          this.pageNo=pageNo
          this.pageSize=pageSize
          console.log(pageNo)
          console.log(pageSize)
          axios.get("http://localhost:8082/flight/getFlightsPage",{
            params:{
              pageNo:this.pageNo,
              pageSize:this.pageSize
            }
          }).then(resp=>{
            console.log("------->",resp)
            this.flightList=resp.data.data.page
            this.total=resp.data.data.total
          })
        },
        /**
         * 删除机票
         */
         deleteTicket(row){
          
          // 跳出删除确认和取消弹出框
           this.$confirm('是否删除', '删除提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          axios.get("http://localhost:8082/ticket/deleteTicketByTicketId",{
            params:{
              ticketId:row.ticketId
            }
          }).then(resp=>{
            console.log(resp)
            if(resp.data.code==0){
              this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.Toticket(row.flightId)
          }else {
              this.$message({
                type: 'error',
                message: resp.data.message
              });
            }
          });
        }).catch(() => {
          this.$message({
            type: 'error',
            message: '已取消删除'
          });          
        });
        },
        
        /**
         * 删除航班
         */
        deleteFlight(flightId){
          console.log(flightId)
          // 跳出删除确认和取消弹出框
           this.$confirm('是否删除', '删除提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          axios.get("http://localhost:8082/flight/deleteFlight",{
            params:{
              flightId:flightId
            }
          }).then(resp=>{
            console.log(resp)
            if(resp.data.code==0){
              this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getFlightPage(this.pageNo,this.pageSize)
          }else {
              this.$message({
                type: 'error',
                message: resp.data.message
              });
            }
          });
        }).catch(() => {
          this.$message({
            type: 'error',
            message: '已取消删除'
          });          
        });
        },
        /**
         * 表单重置
         */
         resetForm(flightForm){
          //只能重置成flight对象的数据
          this.$refs[flightForm].resetFields();
          this.flight=this.$options.data().flight
         },
         /**
          * 添加机票
          */
          addTicketBtn(formName){
          this.$refs[formName].validate((valid) => {
          if (valid) {
            this.ticket.flightId=this.flight.flightId
            console.log("航班号：",this.ticket.flightId)
            axios.post("http://localhost:8082/ticket/addTicket",JSON.stringify(this.ticket),{
              headers:{
              'Content-Type':'application/json'
            }
            }).then(resp=>{
              console.log(resp)
              if(resp.data.code===0){
                //关闭对话框
                this.dialogTableVisibleAddTicket1=false
                //获取分页数据
                this.Toticket(this.ticket.flightId)
                console.log("航班号+++++++++++++：",this.flight.flightId)
                this.flight.flightId=''
              }else{
                this.$message.error(resp.data.data.message)            
              }
            }
            )
          } else {
            this.$message.error("添加机票失败")
            return false;
          }
        });
          },
         /**
          * 添加航班时添加机票
          */
         addTicketAndFlightBtn(formName){
          this.$refs[formName].validate((valid) => {
          if (valid) {
            const flightAndTicket = {
              flight: this.flight,
              ticket: this.ticket
            };
            console.log("++++++++++++",this.flight)
            console.log("Serialized flightAndTicket:", JSON.stringify(flightAndTicket));
            axios.post("http://localhost:8082/flight/addFlightAndTicket",JSON.stringify(flightAndTicket),{
              headers:{
              'Content-Type':'application/json'
            }
            }).then(resp=>{
              console.log(resp)
              if(resp.data.code===0){
                //关闭对话框
                this.dialogTableVisible=false
                this.dialogTableVisibleAddTicket=false
                //获取分页数据
                this.getFlightPage(this.pageNo,this.pageSize)
              }else{
                this.$message.error(resp.data.data.message)
              }
            }
            )
          } else {
            this.$message.error("添加航班失败")
            return false;
          }
        });
         },
         /**
          * 添加航班
          */
         addFlightBtn(){
          this.dialogTableVisibleAddTicket=true
         },
         /**
          * 查询按钮
          */
          selectFlightBtn() {
            console.log('Current flight:', this.flight);
            axios.get("http://localhost:8082/flight/getFlightList", {
            params: {
              flightNumber: this.flight.flightNumber,
              airline: this.flight.airline,
              departureAirport: this.flight.departureAirport,
              arrivalAirport: this.flight.arrivalAirport, 
              departureCity: this.flight.departureCity,
              arrivalCity: this.flight.arrivalCity,
              start: this.flight.departureTime, 
              end: this.flight.arrivalTime, 
              status: this.flight.status
            }
          }).then(resp => {
            if(resp.data.code===0){
              console.log(resp)
                //关闭对话框
                this.dialogTableVisibleSelect=false
                this.isPaginationVisable=false
                this.flightList = resp.data.data;
              }else{
                this.$message.error(resp.data.message)}
                // this.flightList = resp.data.data.page;
                // this.total = resp.data.data.total;
          });
        },

         /**
          * 查询显示页面
          */
         toSelectFlight(){
          this.dialogTableVisibleSelect=true
         },
         /**
          * 添加航班页面表单重置
          */
         toAddFlight(){
          this.dialogTableVisible=true
         },
         
         /**
          * 弹出更新航班页面
          */
         toEditFlight(row){
          this.dialogTableVisibleUpdate=true
          console.log(row)
          this.flight.flightId=row.flightId
          this.flight.flightNumber=row.flightNumber
          this.flight.departureCity=row.departureCity
          this.flight.departureAirport=row.departureAirport 
          this.flight.arrivalCity=row.arrivalCity
          this.flight.arrivalAirport=row.arrivalAirport
          this.flight.departureTime=row.departureTime
          this.flight.arrivalTime=row.arrivalTime
          this.flight.airline=row.airline
          this.flight.status=row.status
         },
         /**
          * 弹出更新机票页面
          */
          toEditTicket(row){
            this.dialogTableVisibleUpdateTicket=true,
            console.log(row)
            this.ticket.ticketId=row.ticketId,
            this.ticket.flightId=row.flightId,
            this.ticket.count=row.count,
            this.ticket.price=row.price,
            this.ticket.type=row.type
          },
          /**
           * 更新机票按钮
           */
           updateTicketBtn(){
              axios.post("http://localhost:8082/ticket/updateTicket",JSON.stringify(this.ticket),{
                headers:{
              'Content-Type':'application/json'
                }
              }).then(resp=>{
              console.log(resp)
              if(resp.data.code===0){
                //关闭对话框
                this.dialogTableVisibleUpdateTicket=false
                //获取分页数据
                this.Toticket(this.ticket.flightId)
                console.log("---------------====",this.flight.flightId)
              }else{
                this.$message.error(resp.data.data.message)
              }
            }
            )
           },
         /**
          * 更新航班按钮
          */
          updateFlightBtn(){
            axios.post("http://localhost:8082/flight/updateFlight",JSON.stringify(this.flight),{
              headers:{
              'Content-Type':'application/json'
            }
            }).then(resp=>{
              console.log(resp)
              if(resp.data.code===0){
                //关闭对话框
                this.dialogTableVisibleUpdate=false
                //获取分页数据
                this.getFlightPage(this.pageNo,this.pageSize)
              }else{
                this.$message.error(resp.data.data.message)
              }
            }
            )
          }
      }
    }
    
  </script>
  <style>
  

</style>